package pl.vm.domain;

import java.util.HashSet;
import java.util.Set;

/**
 * Class representing real teams and squads
 * @author krzysztof.graczyk
 *
 */
public class OfficialTeam {

	private String name;
	private Set<Player> players = new HashSet<>();
	
	public OfficialTeam(String name) {
		super();
		this.setName(name);
	}

	public boolean addPlayer(Player player) {
		return players.add(player);
	}
	
	public boolean removePlayer(Player player) {
		return players.remove(player);
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Set<Player> getPlayers() {
		return this.players;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		OfficialTeam other = (OfficialTeam) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("[" + this.name + "]:");
		for (Player player : this.players) {
			builder.append(player.toString());
		}
		return builder.toString();
	}
}
